//
//  UIBarButtonItem+Extension.swift
//  MTWeiBo
//
//  Created by user on 2017/7/22.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit
//指定函数不能定义在extension里面，存储属性也不能定义
extension UIBarButtonItem {
    //扩展便利构造函数, 函数还可以是指默认参数提供默认值
    convenience  init(title: String,target: Any?,action: Selector, imageName: String? = nil) {
        let butten = UIButton()
        //添加点击事件
        butten.addTarget(target, action: action, for: .touchUpInside)
        //设置标题
        butten.setTitle(title, for: .normal)
        butten.setTitleColor(UIColor.darkGray, for: .normal)
        butten.setTitleColor(UIColor.orange, for: .highlighted)
        //字体大小
        butten.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        //默认参数
        if imageName != nil {
            butten.setImage(UIImage(named: imageName!), for: .normal)
        }
        //按钮大小
        butten.sizeToFit()
        
        
        self.init(customView: butten)
    }
    
}
